/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Project: app2022 - Ex3
 * <p>Powered by webrx On 2022-01-18 14:10:25
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex3 {

    public static Map<String, List<String>> map = new HashMap<>();

    public static void main(String[] args) {
        count(System.getProperty("user.dir"));
        //System.out.println(map);
        map.forEach((k, v) -> System.out.printf("%s = %d %n", k, v.size()));
        //map.forEach((k, v) -> System.out.printf("%s = %d %n %s %n", k, v.size(), v));
    }

    public static void count(String dir) {
        count(new File(dir));
    }


    public static void count(File dir) {
        if (dir.isDirectory()) {
            for (File t : dir.listFiles()) {
                if (t.isDirectory()) {
                    count(t);
                } else {
                    String fn = t.getName();
                    String ext = fn.lastIndexOf(".") == -1 ? "未知" : fn.substring(fn.lastIndexOf(".") + 1);
                    if (map.containsKey(ext)) {
                        List<String> list = map.get(ext);
                        list.add(t.getAbsolutePath());
                        map.put(ext, list);
                    } else {
                        List<String> list = new ArrayList<String>();
                        list.add(t.getAbsolutePath());
                        map.put(ext, list);
                    }
                }
            }
        }
    }

}
